<template>
	<view class="app">
		<view class="panel">
			<view class="flex-col setpidpage">
				<view class="flex justify-between inputitem">
					<view>推广员ID</view>
					<view><input v-model="user_id" placeholder="请输入推广员ID" /></view>
				</view>
				<view class="flex justify-center items-center btn-save">
					<button @tap.stop="query">查询</button>
				</view>
			</view>
		</view>
		
		<view class="panel">
			<view class="flex-col setpidpage">
				<view class="flex justify-between inputitem">
					<view>真实姓名</view>
					<view style="border-bottom: 1px solid #f0f0f0; line-height: 22px; height: 22px;">{{realname}}</view>
				</view>
				<view class="flex justify-between inputitem" style="margin-top: 8px;">
					<view>注册手机</view>
					<view style="border-bottom: 1px solid #f0f0f0; line-height: 22px; height: 22px;">{{mobile}}</view>
				</view>
			</view>
		</view>
		
		
		<view class="panel">
			<view class="flex-col setpidpage">
				<view class="flex justify-between inputitem">
					<view>推广权限</view>
					<view>
						<label class="flex" style="align-items: center;">
							<text>{{is_freeze==1?'关':'开'}}</text>
							<switch color="#38987c" style="transform:scale(0.7)" :checked="is_freeze?false:true" @change="changeis_freeze(is_freeze)"></switch>
						</label>
					</view>
				</view>
				<view class="flex justify-between inputitem">
					<view>分成比例</view>
					<view class="flex" style="align-items: center;"><input v-model="channel_rate" placeholder="请输入分成比例" />%</view>
				</view>
				<view class="flex justify-center items-center btn-save">
					<button @tap.stop="save2">立即设置</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var that,App=getApp(),Comm=getApp().comm;
	export default {
		data() {
			return {
				user_id:'',
				realname:'',
				mobile:'',
				ali_realname:'',
				ali_account:'',
				channel_rate:0,
				is_freeze:0
			}
		},
		onLoad() {
			that=this;
		},
		methods: {
			query(){
				if(!/^\d+$/.test(this.user_id)){
					uni.showToast({icon:'none',title:'推广员ID有误'});
					return;
				}
				this.comm.http('/api/tool/querychannel',{user_id:this.user_id}).then(res=>{
					if(res.code==0){
						uni.showToast({icon:'none',title:res.msg});
						return;
					}else{
						that.realname=res.data.realname;
						that.mobile=res.data.mobile;
						that.channel_rate=res.data.channel_rate;
						that.is_freeze=res.data.is_freeze;
					}
				});
			},
			changeis_freeze(e){
				this.is_freeze=e==0?1:0;
			},
			save2(){
				if(!/^\d+$/.test(this.user_id)){
					uni.showToast({icon:'none',title:'推广员ID有误'});
					return;
				}
				if(!/^\d+$/.test(this.channel_rate)){
					uni.showToast({icon:'none',title:'分成比例有误'});
					return;
				}
				console.log(this.channel_rate,this.is_freeze);
				this.comm.http('/api/tool/setchannelrate',{user_id:this.user_id,channel_rate:this.channel_rate,is_freeze:this.is_freeze}).then(res=>{
					uni.showToast({icon:'none',title:res.msg});
				});
				
			}
		}
	}
</script>

<style lang="scss">
	.setpidpage{
		.inputitem{
			align-items: center;
			view:nth-child(2){
				flex: 1;margin-left: 8px;
				input{
					height:40px; width: 100%; border-bottom: 1px solid #f0f0f0; font-size: 13px;
				
				}
			}

		}
		.tips{
			font-size: 12px; color: #999; padding: 8px 0; display: block;
		}
	}
</style>
